<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/vbase/init.jsp"%>
<%@ page import="com.velcro.workflow.form.model.Formlayout"%>
<%@ page import="com.velcro.workflow.form.service.FormlayoutService"%>
<%@ page import="com.velcro.workflow.form.model.Forminfo"%>
<%@ page import="com.velcro.workflow.form.service.ForminfoService"%>
<%@ page import="com.velcro.workflow.form.model.Formlink"%>
<%@ page import="com.velcro.workflow.form.service.FormlinkService"%>
<%@ page import="com.velcro.workflow.form.model.Formfield"%>
<%@ page import="com.velcro.workflow.form.service.FormfieldService"%>
<%@ page import="com.velcro.workflow.util.FormLayoutTranslate"%>
<%@ page import="com.velcro.base.Page"%>

<%

String fieldid=request.getParameter("fieldid");
String forminfoid=request.getParameter("forminfoid");

ForminfoService forminfoService=(ForminfoService)BaseContext.getBean(getServletContext(),"forminfoService");
Forminfo forminfo = (Forminfo)forminfoService.getForminfoById(forminfoid);

boolean bSystable = false;
if("402881e60c85ac00010c864dfcc20057".equals(forminfo.getSelectitemid()))
	bSystable = true;
int formtype = forminfo.getObjtype().intValue();
%>

<html>
<head>
<!--字段属性定义-->
<title><%=labelService.getLabelName(locale,"40288194157d68cd01157e7621210060")%></title>

<script src='/dwr/interface/DataService.js'></script>
<script src='/dwr/engine.js'></script>
<script src='/dwr/util.js'></script>
<script language=javascript src="dialog.js"></script>
<link href='dialog.css' type='text/css' rel='stylesheet'>
<script language="JavaScript">
function setDefaults() {
	document.all("rule").innerHTML = dialogArguments.parent.document.all("<%=fieldid%>_initvaluespan").innerHTML;
	
	document.all("rule").focus();
	storeCaret(document.all("rule"));
	
	
	adjustDialog();
	
}

function addfield(fieldname){
	fieldname = " "+fieldname+" ";
	insertAtCaret(document.all("rule"),fieldname);
	document.all("rule").focus();
}

function append(appstr){

	if(appstr == "SUM" || appstr == "RMB" || appstr == "SQL" || appstr == "MAX" || appstr == "PARM" || appstr == "EQ" || appstr == "NQ" || appstr == "LT" || appstr == "LE" || appstr == "GT" || appstr == "GE"){
		appstr = appstr +"(\"  \") ";
		insertAtCaret(document.all("rule"),appstr);
	}else{
		if(appstr == "0" ||appstr == "1" ||appstr == "2" ||appstr == "3" ||appstr == "4" ||appstr == "5" ||appstr == "6" ||appstr == "7" ||appstr == "8" ||appstr == "9" )
			appstr = appstr;
		else
			appstr = " "+appstr+" ";
		insertAtCaret(document.all("rule"),appstr);
	}
	document.all("rule").focus();
}

function storeCaret (textEl) {
	if (textEl.createTextRange) 
	textEl.caretPos = document.selection.createRange().duplicate();    
}

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
	var caretPos = textEl.caretPos;
	caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text;      
	}      
	else        
	textEl.value  = text;
    
} 

function reset(){
	document.all("rule").innerHTML = "";	
	document.all("rule").focus();
}

function save(){
	var sHtml = document.all("rule").innerHTML;	
	dialogArguments.parent.document.all("<%=fieldid%>_initvalue").value = sHtml;
	dialogArguments.parent.document.all("<%=fieldid%>_initvaluespan").innerHTML = sHtml;
	window.close();
	
}

function cancel(){
	window.close();
}

	function getformfield(formid){
       	DataService.getValues(createList,"select f.id,l.labelname from formfield f,label l where f.labelname=l.id and f.formid='"+formid+"' and f.labelname is not null  and f.isdelete is null");
       	return true;
    }
    function createList(data)
	{
	    DWRUtil.removeAllOptions("objfieldid");
	    DWRUtil.addOptions("objfieldid", data,"id","labelname");
	}
	
	
function cool_webcontrol(control)
{

  var id = "$"+control.value+"$";
  
	insertAtCaret(document.all("rule"),id);
	document.all("rule").focus();
  	
}
	
</script>
<base target="_self">
</head>

<body topmargin="0" leftmargin="0" style="border: 0; margin: 0;"
	scroll="no" onLoad="setDefaults()">

	<table width="100%" height=220 border="0" cellspacing="1"
		style="width: 500px; height: 380px;" cellpadding="3" align="center"
		valign=top id=tabDialogSize>
		<tr>
			<td colspan=3>s <textarea class="inputStyle" name="rule" cols=67
					rows=8 ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);"
					ONKEYUP="storeCaret(this);">  
</textarea>
			</td>
		</tr>
		<tr class="TableHeader" height=20>
			<td align="center"><b><%=labelService.getLabelName(locale,"40288194157d68cd01157e7677110061") %>
			</b></td>
			<!--关联表单-->
			<td align="center"><b><%=labelService.getLabelName(locale,"40288194157d68cd01157e76bd900062") %></b></td>
			<!--表单字段 -->
			<td align="center" colspan=2><b><%=labelService.getLabelName(locale,"402881eb0c9fadb1010c9fd1a069000e") %></b></td>
			<!-- 操作 -->
		</tr>
		<tr height=160>
			<td align="center" width=120><select size=8 name="objformid"
				style="width: 120" onchange="javascript:getformfield(this.value);">
					<option value="<%=forminfoid%>" selected><%=labelService.getLabelName(locale,((Forminfo)forminfoService.getForminfoById(forminfoid)).getObjname())%></option>
					<%if(formtype==1){
      		String strHql="from Formlink where oid='"+forminfoid+"' order by typeid desc";
			List list = ((FormlinkService)BaseContext.getBean(getServletContext(),"formlinkService")).findFormlink(strHql);
		
		    for(int i=0;i<list.size();i++)
		    {
		        Formlink formlink=(Formlink)list.get(i);
		%>
					<option value="<%=formlink.getPid()%>"><%=labelService.getLabelName(locale,((Forminfo)forminfoService.getForminfoById(formlink.getPid())).getObjname())%></option>
					<%}
		}%>
			</select></td>
			<td align="center" width=120><select size=8 name="objfieldid"
				style="width: 120" ondblclick="cool_webcontrol(this)">
					<%
      		String strHql="from Formfield where formid='"+forminfoid+"' and labelname is not null and isdelete is null  order by id";
			List list = ((FormfieldService)BaseContext.getBean(getServletContext(),"formfieldService")).findFormfield(strHql);
		
		    for(int i=0;i<list.size();i++)
		    {
		        Formfield formfield=(Formfield)list.get(i);
		        
		      	String showValue = formfield.getId();
		%>
					<option value="<%=showValue%>"><%=labelService.getLabelName(locale,formfield.getLabelname())%></option>
					<%}
			String equal=labelService.getLabelName(locale,"40288194157d68cd01157e5edad10058");//等于
			String notEqual=labelService.getLabelName(locale,"40288194157d68cd01157e609e7a0059");//不等于
			String lessthen=labelService.getLabelName(locale,"40288194157d68cd01157e66c2ed005e");//小于
			String lessthenEqual=labelService.getLabelName(locale,"40288194157d68cd01157e689163005f");//小于等于
			String morethen=labelService.getLabelName(locale,"40288194157d68cd01157e633d70005c");//大于
			String morethenEqual=labelService.getLabelName(locale,"40288194157d68cd01157e666982005d");//大于等于
			String sum=labelService.getLabelName(locale,"40288194157d68cd01157ea3a3560067");//加和
			String RMB=labelService.getLabelName(locale,"40288194157d68cd01157ea3f1c40068");//金额转换
			String sql=labelService.getLabelName(locale,"40288194157d68cd01157ea4dc44006a");//SQL语句
			String max=labelService.getLabelName(locale,"40288194157d68cd01157ea5304f006b");//最大值
			String getparamet=labelService.getLabelName(locale,"40288194157d68cd01157ea57f2b006c");//获取参数
			String currentdate=labelService.getLabelName(locale,"40288194157d68cd01157e9f56140063");//当前日期
			String currenttime=labelService.getLabelName(locale,"4028819415832573011583afce13003a");//当前时间
			String currenuser=labelService.getLabelName(locale,"40288194157d68cd01157ea31b980066");//当前用户
			String currentdept=labelService.getLabelName(locale,"40288194157d68cd01157ea4707a0069");//当前部门
			%>
			</select></td>
			<td align="center" width=240 height=120>
				<table width="100%" height=120 border="0" cellspacing="0"
					cellpadding="3" align="center" valign=top>
					<tr>
						<td width=70><button style="width: 50"
								onclick="append('EQ');" title="<%=equal%>">=</button></td>
						<td width=70><button style="width: 50"
								onclick="append('NQ');" title="<%=notEqual%>">!=</button></td>
						<td width=140><button style="width: 100"
								onclick="append('$currentdate$');" title="<%=currentdate%>">
								<%=currentdate%>
							</button></td>
					</tr>
					<tr>
						<td width=70><button style="width: 50"
								onclick="append('LT');" title="<%=lessthen%>"><</button></td>
						<td width=70><button style="width: 50"
								onclick="append('LE');" title="<%=lessthenEqual %>"><=
							</button></td>
						<td width=140><button style="width: 100"
								onclick="append('$currenttime$');" title="<%=currenttime %>">
								<%=currenttime %>
							</button></td>
					</tr>
					<tr>
						<td width=70><button style="width: 50"
								onclick="append('GT');" title="<%=morethen %>">></button></td>
						<td width=70><button style="width: 50"
								onclick="append('GE');" title="<%=morethenEqual %>">>=
							</button></td>
						<td width=140><button style="width: 100"
								onclick="append('$currentuser$');" title="<%=currenuser %>">
								<%=currenuser %>
							</button></td>
					</tr>
					<tr>
						<td width=70><button style="width: 50"
								onclick="append('SUM');" title="<%=sum%>">SUM</button></td>
						<td width=70><button style="width: 50"
								onclick="append('RMB');" title="<%=RMB %>">RMB</button></td>
						<td width=140><button style="width: 100"
								onclick="append('$currentorgunit$');" title="<%=currentdept %>">
								<%=currentdept %>
							</button></td>
					</tr>
					<tr>
						<td width=70><button style="width: 50"
								onclick="append('SQL');" title="<%=sql %>">SQL</button></td>
						<td width=70><button style="width: 50"
								onclick="append('MAX');" title="<%=max %>">MAX</button></td>
						<td width=140><button style="width: 100"
								onclick="append('PARM');" title="<%=getparamet %>">
								<%=getparamet %>
							</button></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr valign=top>
			<td valign=top align=right colspan=3>
				<button style="width: 80" onclick="reset();">
					<%=labelService.getLabelName(locale,"40288194157d68cd01157ea6159e006d")%></button>&nbsp;&nbsp;&nbsp;&nbsp;<!--重置-->
				<button style="width: 80" onclick="save();"><%=labelService.getLabelName(locale,"402881eb0bcbfd19010bcc6e71870022")%></button>&nbsp;&nbsp;&nbsp;&nbsp;<!-- 确定 -->
				<button style="width: 80" onclick="cancel();"><%=labelService.getLabelName(locale,"402881eb0bcbfd19010bcc6f1e6e0023")%></button>&nbsp;&nbsp;&nbsp;&nbsp;<!-- 取消 -->
			</td>
		</tr>
	</table>
</body>
</FORM>
</html>